Skip to content

git_cmd: read only the repository configuration in tests - #902

Open
sendaoYan wants to merge 1 commit into
sashiko-dev:mainfrom
sendaoYan:fix-897-test-git-config
Open

sendaoYan wants to merge 1 commit into
sashiko-dev:mainfrom
sendaoYan:fix-897-test-git-config

Conversation

@sendaoYan

Copy link
Copy Markdown
Contributor

Summary

make check-pr fails on any developer machine whose global git config rewrites
GitHub URLs:

failures:
    baseline::tests::test_fork_origin_uses_configured_project

git remote -v applies url.<base>.insteadOf, so a [url "git@github.com:"]
block turns the https://github.com/... URL a fixture added into
git@github.com:..., and the assertion compares two different strings. CI
never sees it because the runner has no such configuration.

Fixes #897.

Changes

git_cmd is the single place every git command in the crate is built, and it
already strips the GIT_DIR family so that an inherited environment cannot
redirect a command at another repository. This extends the same idea to the
configuration files:

  • TEST_CONFIG_FILES (#[cfg(test)]) names GIT_CONFIG_GLOBAL and
    GIT_CONFIG_SYSTEM, both set to /dev/null.
  • git_command! applies them to every in_dir, in_dir_async and
    detached_async command in test builds.

Production code keeps honouring the caller's configuration, which decides
which credentials a fetch uses and which URL a remote really points at. Only
the tests, which build throwaway repositories and compare git's answers
against the values they set up themselves, are isolated.

test_commands_read_only_the_repository_configuration asserts both variables
on all three constructors.

Testing

  • make check-pr on a machine whose ~/.gitconfig contains the reproducing
    insteadOf block: all tests pass (1758 lib tests, plus the binary and
    integration suites).
  • Without the fix, baseline::tests::test_fork_origin_uses_configured_project
    fails at src/baseline.rs:2462 with
    git@github.com:contributor/renamed-tree.git on the left and
    https://github.com/contributor/renamed-tree.git on the right.

The test suite builds throwaway repositories and compares git's answers
against the values it set up itself. A url.<base>.insteadOf rewrite in
the developer's ~/.gitconfig or system configuration changes those
answers, because git remote -v prints the rewritten URL, so
baseline::tests::test_fork_origin_uses_configured_project fails on any
machine that clones GitHub over SSH:

  left:  RemoteTarget { url: "git@github.com:contributor/renamed-tree.git" }
  right: RemoteTarget { url: "https://github.com/contributor/renamed-tree.git" }

Production code has to honour the caller's configuration: it decides
which credentials a fetch uses and which URL a remote really points at,
so the isolation is restricted to test builds. There the git_command!
macro points GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM at /dev/null, and
every git command built here reads the repository's own configuration
and nothing else.

Closes: sashiko-dev#897
Signed-off-by: Sendao Yan <yansendao@126.com>
@sashiko-bot

sashiko-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown

Sashiko review

✓ No issues found across 1 commit.

Full review log on sashiko.sashiko.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make check-pr fails when the developer's global git config rewrites GitHub URLs

1 participant